home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / UI / Window.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  55.4 KB  |  2,058 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Window.cpp
  3.  
  4.     Contains:    Implementation of class ODWindow
  5.  
  6.     Owned by:    Chris Linn
  7.  
  8.     Copyright:    © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <6>     6/21/96    CSL        1356527: Doc windows are shown off-screen
  13.                                     if monitor configuration changes.
  14.          <5>     6/14/96    CSL        1316010: Document window disappears forever
  15.                                     on save if WindowShaded
  16.          <4>     5/24/96    jpa        1246074: Added missing SOM_CATCH_ALL's.
  17.          <2>     3/15/96    VL        1302780: Added GetFacetUnderPointForDrag so
  18.                                     that we can ignore selection when we try to
  19.                                     find the facet under mouse point.
  20.  
  21.     To Do:
  22.     
  23.     In Progress:
  24.         
  25. */
  26.  
  27. #define ODWindow_Class_Source
  28.  
  29.  
  30.  
  31. #ifndef _ALTPOINT_
  32. #include "AltPoint.h"            // Use C++ savvy XMPPoint and XMPRect
  33. #endif
  34.  
  35.  
  36. #ifndef SOM_ODWindow_xih
  37. #define VARIABLE_MACROS
  38. #include <Window.xih>
  39. #endif
  40.  
  41. #ifndef _PLFMDEF_
  42. #include "PlfmDef.h"
  43. #endif
  44.  
  45. #ifndef _TEMPOBJ_
  46. #include <TempObj.h>
  47. #endif
  48.  
  49. #ifndef SOM_ODStorageUnit_xh
  50. #include <StorageU.xh>
  51. #endif
  52.  
  53. #ifndef SOM_ODStorageSystem_xh
  54. #include <ODStor.xh>
  55. #endif
  56.  
  57. #ifndef SOM_ODDraft_xh
  58. #include <Draft.xh>
  59. #endif
  60.  
  61. #ifndef SOM_ODDocument_xh
  62. #include <Document.xh>
  63. #endif
  64.  
  65. #ifndef SOM_ODContainer_xh
  66. #include <ODCtr.xh>
  67. #endif
  68.  
  69. #ifndef SOM_ODSession_xh
  70. #include <ODSessn.xh>
  71. #endif
  72.  
  73. #ifndef SOM_ODPart_xh
  74. #include <Part.xh>
  75. #endif
  76.  
  77. #ifndef SOM_ODDispatcher_xh
  78. #include <Disptch.xh>
  79. #endif
  80.  
  81. #ifndef SOM_ODWindowState_xh
  82. #include <WinStat.xh>
  83. #endif
  84.  
  85. #ifndef SOM_ODArbitrator_xh
  86. #include <Arbitrat.xh>
  87. #endif
  88.  
  89. #ifndef SOM_ODFrame_xh
  90. #include <Frame.xh>
  91. #endif
  92.  
  93.  
  94. #ifndef SOM_ODFacetIterator_xh
  95. #include <FacetItr.xh>
  96. #endif
  97.  
  98. #ifndef SOM_ODFacet_xh
  99. #include <Facet.xh>
  100. #endif
  101.  
  102. #ifndef SOM_ODCanvas_xh
  103. #include <Canvas.xh>
  104. #endif
  105.  
  106. #ifndef SOM_ODShape_xh
  107. #include <Shape.xh>
  108. #endif
  109.  
  110. #ifndef SOM_ODTransform_xh
  111. #include <Trnsform.xh>
  112. #endif
  113.  
  114. #ifndef _ODUTILS_
  115. #include <ODUtils.h>
  116. #endif
  117.  
  118. #ifndef SOM_Module_OpenDoc_Foci_defined
  119. #include <Foci.xh>
  120. #endif
  121.  
  122. #ifndef _STDTYPIO_
  123. #include <StdTypIO.h>
  124. #endif
  125.  
  126. #ifndef _ITEXT_
  127. #include "IText.h"
  128. #endif
  129.  
  130. #ifndef __TOOLUTILS__
  131. #include <ToolUtils.h>
  132. #endif
  133.  
  134. #ifndef __RESOURCES__
  135. #include <Resources.h>
  136. #endif
  137.  
  138. #ifndef __OSUTILS__
  139. #include <OSUtils.h>    // SysBeep etc.
  140. #endif
  141.  
  142. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  143. #include <StdTypes.xh>
  144. #endif
  145.  
  146. #ifndef SOM_Module_OpenDoc_StdProps_defined
  147. #include <StdProps.xh>
  148. #endif
  149.  
  150. #ifndef _EXCEPT_
  151. #include "Except.h"
  152. #endif
  153.  
  154. #ifndef __OCESTANDARDMAIL__
  155. #include <OCEStandardMail.h>
  156. #endif
  157.  
  158. #ifndef __OCEERRORS__
  159. #include <OCEErrors.h>
  160. #endif
  161.  
  162. #ifndef SOM_ODMenuBar_xh
  163. #include <MenuBar.xh>
  164. #endif
  165.  
  166. #ifndef SOM_Module_OpenDoc_Commands_defined
  167. #include <CmdDefs.xh>
  168. #endif
  169.  
  170. #ifndef _PASCLSTR_
  171. #include "PasclStr.h"
  172. #endif
  173.  
  174. #ifndef _CONSTDEF_
  175. #include "ConstDef.h"
  176. #endif
  177.  
  178. #ifndef __GESTALTEQU__
  179. #include <GestaltEqu.h>
  180. #endif
  181.  
  182. #ifndef __DIALOGS__
  183. #include <Dialogs.h>
  184. #endif
  185.  
  186. #ifndef _ODDEBUG_
  187. #include "ODDebug.h"
  188. #endif
  189.  
  190. #ifndef _DOCUTILS_
  191. #include <DocUtils.h>
  192. #endif
  193.  
  194. #ifndef _STORUTIL_
  195. #include <StorUtil.h>
  196. #endif
  197.  
  198. #ifndef _ISOSTR_
  199. #include "ISOStr.h"
  200. #endif
  201.  
  202. #ifndef _DSPUTILM_
  203. #include "DspUtilM.h" 
  204. #endif
  205.  
  206. #pragma segment ODWindow
  207.  
  208. #include "WindowB.cpp"    // Platform-independent methods, if any
  209.  
  210. #define ODDebugActivates 0
  211.  
  212. //==============================================================================
  213. // Constants
  214. //==============================================================================
  215.  
  216. // Check ErrorDef.idl before adding any new codes here, to make sure they're unique.
  217. const ODError kODErrInvalidPlatformWindow         = -29828;
  218. const ODError kODErrInvalidWindow                = -29827;
  219.  
  220. // TÇ: This error code was only being used in this file, and then only
  221. // for checking the _fPlatformWindow field of a window at the beginning of
  222. // methods.  It didn't seem to have anything to do with the api.
  223. // That is why I made it private to this file.
  224. // perhaps the error that should be thrown is kODErrObjectNotInitialized?
  225. // kODErrInvalidWindow falls into the same category.
  226.  
  227.  
  228. //==============================================================================
  229. // Types
  230. //==============================================================================
  231.  
  232. //=====================================================================================
  233. // ODWindow Methods
  234. //=====================================================================================
  235.  
  236.  
  237. //-------------------------------------------------------------------------------------
  238. // ODWindow: CommonInitWindow    
  239. //-------------------------------------------------------------------------------------
  240.  
  241. SOM_Scope void  SOMLINK ODWindowCommonInitWindow(ODWindow *somSelf, Environment *ev)
  242. {
  243.     ODWindowData *somThis = ODWindowGetData(somSelf);
  244.     ODWindowMethodDebug("ODWindow","CommonInitWindow");
  245.     
  246.     SOM_TRY
  247.  
  248.         _fSession = (ODSession*) _fDraft->GetDocument(ev)->GetContainer(ev)->GetStorageSystem(ev)->GetSession(ev);    
  249.         _fArbitrator = _fSession->GetArbitrator(ev);
  250.         _fSelectionFocus = _fSession->Tokenize(ev,kODSelectionFocus);
  251.     
  252.     SOM_CATCH_ALL
  253.     SOM_ENDTRY
  254. }
  255.  
  256.  
  257. //-------------------------------------------------------------------------------------
  258. // ODWindow: InitWindow                
  259. //-------------------------------------------------------------------------------------
  260.  
  261. SOM_Scope void  SOMLINK ODWindowInitWindow (ODWindow *somSelf, Environment *ev,
  262.         ODPlatformWindow    platformWindow, 
  263.         ODType                frameType,
  264.         ODBoolean            isRootWindow,
  265.         ODBoolean            isResizable,
  266.         ODBoolean            isFloating,
  267.         ODBoolean            shouldSave,
  268.         ODBoolean            shouldDispose,
  269.         ODPart*                rootPart,
  270.         ODTypeToken            viewType,
  271.         ODTypeToken            presentation,
  272.         ODFrame*            sourceFrame)
  273. {
  274.     ODWindowData *somThis = ODWindowGetData(somSelf);
  275.     ODWindowMethodDebug("ODWindow","InitWindow");
  276.  
  277.     SOM_TRY
  278.     
  279.         /* Moved from somInit. SOM itself sets fields to zero
  280.         _fPlatformWindow = kODNULL;
  281.         _fRootFacet = kODNULL;
  282.         _fSourceFrame = kODNULL;
  283.         _fSession = kODNULL;
  284.         _fIsRootWindow = kODTrue;
  285.         _fShouldSave = kODTrue;
  286.         _fIsResizable = kODFalse;
  287.         _fIsFloating = kODFalse;
  288.         _fWasVisible = kODFalse;
  289.         _fShouldShowLinks = kODFalse;
  290.         _fArbitrator = kODNULL;
  291.         
  292.         _fStorageUnit = kODNULL;
  293.         _fIsDirty = kODFalse;
  294.         _fDraft = kODNULL;
  295.         
  296.         _fShouldAdjustOnOpen = kODFalse;
  297.         _fInBackground = kODFalse;
  298.         _fIsActive = kODFalse;
  299.         _fSelectionFocus = 0;
  300.         */
  301.         _fShouldDispose    = shouldDispose;    
  302.         
  303.         somSelf->InitRefCntObject(ev);
  304.  
  305. #if ODDebug
  306.         if (shouldSave && ODISOStrEqual(frameType, kODNonPersistentFrameObject)) 
  307.             WARN("InitWindow: shouldSave is TRUE, but root frame is nonpersistent ");
  308.  
  309. #endif
  310.         
  311.         _fPlatformWindow = platformWindow;
  312.         _fIsRootWindow    = isRootWindow;
  313.         _fIsResizable    = isResizable;
  314.         _fIsFloating    = isFloating;
  315.         if (sourceFrame)
  316.             sourceFrame->Acquire(ev);
  317.         _fSourceFrame    = sourceFrame;
  318.         _fDraft            = rootPart->GetStorageUnit(ev)->GetDraft(ev);
  319.         _fDraft->Acquire(ev);
  320.         if (!HAS_WRITE_ACCESS(_fDraft->GetPermissions(ev)))
  321.         {
  322.             shouldSave = kODFalse;
  323.             frameType = kODNonPersistentFrameObject;
  324.         }
  325.     
  326.         _fShouldSave     = shouldSave;
  327.     
  328.         somSelf->CommonInitWindow(ev);
  329.         
  330.         somSelf->CreateRootFrame(ev, frameType, viewType, presentation, rootPart);
  331.     
  332.         _fIsDirty = kODTrue;
  333.         _fShouldAdjustOnOpen = kODTrue;
  334.     
  335.     SOM_CATCH_ALL
  336.     SOM_ENDTRY
  337. }
  338. //-------------------------------------------------------------------------------------
  339. // ODWindow: InitWindowForFrame                
  340. //-------------------------------------------------------------------------------------
  341.  
  342. SOM_Scope void  SOMLINK ODWindowInitWindowForFrame (ODWindow *somSelf, Environment *ev,
  343.         ODPlatformWindow    platformWindow, 
  344.         ODFrame*            frame,
  345.         ODBoolean            isRootWindow,
  346.         ODBoolean            isResizable,
  347.         ODBoolean            isFloating,
  348.         ODBoolean            shouldSave,
  349.         ODBoolean            shouldDispose,
  350.         ODFrame*            sourceFrame)
  351. {
  352.     ODWindowData *somThis = ODWindowGetData(somSelf);
  353.     ODWindowMethodDebug("ODWindow","InitWindow");
  354.     
  355.     SOM_TRY
  356.     
  357.         ASSERT(frame != kODNULL, kODErrInvalidFrame);
  358.             
  359.         /* Moved from somInit. SOM itself sets fields to zero
  360.         _fPlatformWindow = kODNULL;
  361.         _fRootFacet = kODNULL;
  362.         _fSourceFrame = kODNULL;
  363.         _fSession = kODNULL;
  364.         _fIsRootWindow = kODTrue;
  365.         _fShouldSave = kODTrue;
  366.         _fIsResizable = kODFalse;
  367.         _fIsFloating = kODFalse;
  368.         _fWasVisible = kODFalse;
  369.         _fShouldShowLinks = kODFalse;
  370.         _fArbitrator = kODNULL;
  371.         
  372.         _fStorageUnit = kODNULL;
  373.         _fIsDirty = kODFalse;
  374.         _fDraft = kODNULL;
  375.         
  376.         _fShouldAdjustOnOpen = kODFalse;
  377.         _fInBackground = kODFalse;
  378.         _fSelectionFocus = 0;
  379.         */
  380.         _fShouldDispose    = shouldDispose;    
  381.  
  382.         somSelf->InitRefCntObject(ev);
  383.  
  384. #if ODDebug
  385.         if (shouldSave && (frame->GetStorageUnit(ev) == kODNULL))
  386.             WARN("InitWindowForFrame: shouldSave is TRUE, but root frame is nonpersistent ");
  387.  
  388. #endif
  389.  
  390.         _fPlatformWindow = platformWindow;
  391.         _fIsRootWindow    = isRootWindow;
  392.         _fIsResizable    = isResizable;
  393.         _fIsFloating    = isFloating;
  394.         if (sourceFrame)
  395.             sourceFrame->Acquire(ev);
  396.         _fSourceFrame    = sourceFrame;
  397.         { 
  398.             TempODPart part = frame->AcquirePart(ev);
  399.             _fDraft            = part->GetStorageUnit(ev)->GetDraft(ev);
  400.             _fDraft->Acquire(ev);
  401.         }
  402.     
  403.         if (!HAS_WRITE_ACCESS(_fDraft->GetPermissions(ev)))
  404.             shouldSave = kODFalse;
  405.     
  406.         _fShouldSave    = shouldSave;
  407.     
  408.         somSelf->CommonInitWindow(ev);
  409.         
  410.         if (frame)
  411.         {
  412.             frame->Acquire(ev);
  413.             frame->SetWindow(ev, somSelf);
  414.         }
  415.         _fRootFrame = frame;
  416.     
  417.         _fIsDirty = kODFalse;
  418.         _fShouldAdjustOnOpen = kODFalse;
  419.         
  420.         ODStorageUnit* frameSU = frame->GetStorageUnit(ev);
  421.         if ((frameSU != kODNULL) && (_fDraft != kODNULL))
  422.         {
  423.             ODID windowPropsID = ODGetStrongSURefProp(ev, frameSU, kODPropWindowProperties, kODStrongStorageUnitRef);
  424.             if (windowPropsID != kODNULLID)
  425.             {
  426.                 _fStorageUnit = _fDraft->AcquireStorageUnit(ev, windowPropsID);
  427.             }
  428.         }
  429.  
  430.     SOM_CATCH_ALL
  431.     SOM_ENDTRY
  432. }
  433.  
  434. //-------------------------------------------------------------------------------------
  435. // ODWindow: Purge
  436. //
  437. // Description
  438. //-------------------------------------------------------------------------------------
  439.         
  440. SOM_Scope ODSize     SOMLINK ODWindowPurge(ODWindow *somSelf, Environment *ev,
  441.         ODSize size)
  442. {
  443.     ODWindowData *somThis = ODWindowGetData(somSelf);
  444.     ODWindowMethodDebug("ODWindow","Purge");
  445.     
  446.     ODSize purgeSize = 0;
  447.     
  448.     SOM_TRY
  449.     
  450.         purgeSize = parent_Purge(somSelf, ev, size);
  451.         
  452.     SOM_CATCH_ALL
  453.         WARN("Error %ld trying to purge in ODWindowPurge",ErrorCode());
  454.         SetErrorCode(kODNoError);        // Eat the exception; Purge should not 
  455.                                         // propagate it because clients function
  456.                                         // fine whether memory was purged or not.
  457.     SOM_ENDTRY
  458.  
  459.     return purgeSize;
  460. }
  461.  
  462. //-------------------------------------------------------------------------------------
  463. // ODWindow: Release
  464. //
  465. // Description
  466. //-------------------------------------------------------------------------------------
  467.         
  468. SOM_Scope void     SOMLINK ODWindowRelease(ODWindow *somSelf, Environment *ev)
  469. {
  470.     ODWindowData *somThis = ODWindowGetData(somSelf);
  471.     ODWindowMethodDebug("ODWindow","Release");
  472.     
  473.     SOM_TRY
  474.  
  475.         parent_Release(somSelf, ev); 
  476.         if (somSelf->GetRefCount(ev) == 0) 
  477.             _fSession->GetWindowState(ev)->ReleaseWindow(ev,somSelf);
  478.  
  479.     SOM_CATCH_ALL
  480.     SOM_ENDTRY
  481. }
  482.  
  483. //-------------------------------------------------------------------------------------
  484. // ODWindow: ~ODWindow                
  485. //
  486. // Description
  487. //-------------------------------------------------------------------------------------
  488.  
  489. SOM_Scope void  SOMLINK ODWindowsomUninit (ODWindow *somSelf)
  490. {
  491.     ODWindowData *somThis = ODWindowGetData(somSelf);
  492.     ODWindowMethodDebug("ODWindow","somUninit");
  493.  
  494.     Environment* ev = somGetGlobalEnvironment();
  495.     //    • Get rid of our window
  496.     if (_fPlatformWindow && _fShouldDispose)
  497.     {
  498.         if (((WindowRecord*)_fPlatformWindow)->windowKind == dialogKind)
  499.             DisposeDialog(_fPlatformWindow);
  500.         else
  501.             DisposeWindow(_fPlatformWindow);
  502.         _fPlatformWindow = kODNULL;
  503.     }
  504.     
  505.     // Storage Unit must be released before draft    
  506.     ODSafeReleaseObject(_fStorageUnit);    
  507.     ODSafeReleaseObject(_fDraft);        
  508.     ODSafeReleaseObject(_fRootFrame);    
  509.     ODSafeReleaseObject(_fSourceFrame); 
  510. }    //     SOMLINK ODWindowsomUninit
  511.  
  512. //-------------------------------------------------------------------------------------
  513. // ODWindow: GetPlatformWindow
  514. //
  515. // Description
  516. //-------------------------------------------------------------------------------------
  517.  
  518. SOM_Scope ODPlatformWindow      SOMLINK ODWindowGetPlatformWindow(ODWindow *somSelf, Environment *ev)
  519. {
  520.     ODWindowData *somThis = ODWindowGetData(somSelf);
  521.     ODWindowMethodDebug("ODWindow","GetPlatformWindow");
  522.  
  523.     return _fPlatformWindow;
  524. }
  525.  
  526. //-------------------------------------------------------------------------------------
  527. // ODWindow: AcquireSourceFrame
  528. //
  529. // Description
  530. //-------------------------------------------------------------------------------------
  531.  
  532. SOM_Scope ODFrame*     SOMLINK ODWindowAcquireSourceFrame(ODWindow *somSelf, Environment *ev) 
  533. {
  534.     ODWindowData *somThis = ODWindowGetData(somSelf);
  535.     ODWindowMethodDebug("ODWindow","AcquireSourceFrame");
  536.     
  537.     SOM_TRY
  538.     
  539.     if (_fSourceFrame)
  540.         _fSourceFrame->Acquire(ev);
  541.  
  542.      SOM_CATCH_ALL
  543.     SOM_ENDTRY
  544.     return _fSourceFrame; 
  545. }
  546.  
  547. //-------------------------------------------------------------------------------------
  548. // ODWindow: SetSourceFrame
  549. //
  550. // Description
  551. //-------------------------------------------------------------------------------------
  552.  
  553. SOM_Scope void     SOMLINK ODWindowSetSourceFrame(ODWindow *somSelf, Environment *ev, 
  554.                                                 ODFrame* frame) 
  555. {
  556.     ODWindowData *somThis = ODWindowGetData(somSelf);
  557.     ODWindowMethodDebug("ODWindow","AcquireSourceFrame");
  558.     
  559.     SOM_TRY
  560.  
  561.         if (frame)
  562.             frame->Acquire(ev);
  563.         if (_fSourceFrame)
  564.             _fSourceFrame->Release(ev);
  565.      
  566.         _fSourceFrame = frame; 
  567.     
  568.     SOM_CATCH_ALL
  569.     SOM_ENDTRY
  570. }
  571.  
  572. //-------------------------------------------------------------------------------------
  573. // ODWindow: GetRootFrame
  574. //
  575. // Description
  576. //-------------------------------------------------------------------------------------
  577.  
  578. SOM_Scope ODFrame*  SOMLINK ODWindowGetRootFrame(ODWindow *somSelf, Environment *ev) 
  579. {
  580.     ODWindowData *somThis = ODWindowGetData(somSelf);
  581.     ODWindowMethodDebug("ODWindow","GetRootFrame");
  582.  
  583.     return _fRootFrame; 
  584. }
  585.         
  586. //-------------------------------------------------------------------------------------
  587. // ODWindow: GetRootFacet
  588. //
  589. // Description
  590. //-------------------------------------------------------------------------------------
  591.  
  592. SOM_Scope ODFacet*  SOMLINK ODWindowGetRootFacet(ODWindow *somSelf, Environment *ev)
  593. {
  594.     ODWindowData *somThis = ODWindowGetData(somSelf);
  595.     ODWindowMethodDebug("ODWindow","GetRootFacet");
  596.  
  597.     return _fRootFacet;
  598. }    
  599.     
  600. //-------------------------------------------------------------------------------------
  601. // ODWindow: CreateRootFrame
  602. // PRIVATE
  603. //
  604. // Description
  605. //-------------------------------------------------------------------------------------
  606.  
  607. SOM_Scope void  SOMLINK ODWindowCreateRootFrame(ODWindow *somSelf, Environment *ev,
  608.         ODType        frameType,
  609.         ODTypeToken    viewType,
  610.         ODTypeToken    presentation,
  611.         ODPart* rootPart)
  612. {
  613.     ODWindowData *somThis = ODWindowGetData(somSelf);
  614.     ODWindowMethodDebug("ODWindow","CreateRootFrame");
  615.  
  616.     ODShape* newShape = kODNULL;ODVolatile(newShape);
  617.     
  618.     SOM_TRY
  619.     
  620.         if (_fPlatformWindow)
  621.         {
  622.             Rect frameShape = _fPlatformWindow->portRect;
  623.             
  624.             TRY
  625.     
  626.                 newShape = new ODShape; // Can't Use factory method because no frame is available yet
  627.                 THROW_IF_NULL(newShape);
  628.                 newShape->InitShape(ev);
  629.                 
  630.             CATCH_ALL
  631.                 ODDeleteObject(newShape); newShape = kODNULL; // must delete before InitShape returns
  632.                 RERAISE;
  633.             ENDTRY
  634.     
  635.             TempODShape tempShape = newShape;    // ensures it's released
  636.             
  637.             ODRect r = _fPlatformWindow->portRect;
  638.             newShape->SetRectangle(ev,&r);
  639.             _fRootFrame = _fDraft->CreateFrame(ev, frameType, (ODFrame*)kODNULL,
  640.                                         newShape, (ODCanvas*)kODNULL,
  641.                                         rootPart, viewType, presentation,
  642.                                         kODFalse,    // isSubframe
  643.                                         kODFalse);    // isOverlaid
  644.             _fRootFrame->SetWindow(ev, somSelf);
  645.         
  646.             if (rootPart && _fSourceFrame)
  647.                 rootPart->AttachSourceFrame(ev, _fRootFrame, _fSourceFrame);
  648.         }
  649.         _fIsDirty = kODTrue;
  650.  
  651.     SOM_CATCH_ALL
  652.     SOM_ENDTRY
  653. }    // CreateRootFrame()
  654.  
  655. //-------------------------------------------------------------------------------------
  656. // ODWindow: CreateRootFacet
  657. //-------------------------------------------------------------------------------------
  658.  
  659. SOM_Scope void  SOMLINK ODWindowCreateRootFacet(ODWindow *somSelf, Environment *ev)
  660. {
  661.     ODWindowData *somThis = ODWindowGetData(somSelf);
  662.     ODWindowMethodDebug("ODWindow","CreateRootFacet");
  663.  
  664.     ODShape* frameShape = kODNULL;
  665.     ODShape* clipShape = kODNULL;
  666.     
  667.     SOM_TRY
  668.     
  669.         frameShape = _fRootFrame->AcquireFrameShape(ev, kODNULL);
  670.         clipShape = frameShape->Copy(ev);
  671.         ODReleaseObject(ev, frameShape);
  672.     
  673.         ODTransform* externalTransform = _fRootFrame->CreateTransform(ev); 
  674.         
  675.         ODWindowState* windowState = _fSession->GetWindowState(ev);
  676.         ODCanvas* rootCanvas = windowState->CreateCanvas(ev, kODQuickDraw,
  677.                                 (ODPlatformCanvas) _fPlatformWindow,
  678.                                 kODTrue,        // isDynamic
  679.                                 kODFalse);        // isOffscreen
  680.     
  681.         _fRootFacet = windowState->CreateFacet(ev, _fRootFrame, clipShape, externalTransform, rootCanvas, kODNULL);
  682.         ODReleaseObject(ev, clipShape);
  683.         ODReleaseObject(ev, externalTransform);
  684.         
  685.         _fRootFrame->FacetAdded(ev,_fRootFacet);
  686.         _fIsDirty = kODTrue;
  687.         
  688.     SOM_CATCH_ALL
  689.     SOM_ENDTRY
  690. }
  691.  
  692. //-------------------------------------------------------------------------------------
  693. // ODWindow: AdjustWindowShape
  694. //
  695. // Description
  696. //-------------------------------------------------------------------------------------
  697.  
  698. SOM_Scope void  SOMLINK ODWindowAdjustWindowShape (ODWindow *somSelf, Environment *ev)
  699. {
  700.     ODWindowData *somThis = ODWindowGetData(somSelf);
  701.     ODWindowMethodDebug("ODWindow","AdjustWindowShape");
  702.     
  703.     SOM_TRY
  704.  
  705.         if (_fPlatformWindow)
  706.         {
  707.             Rect contentRect = _fPlatformWindow->portRect;
  708.             Rect growRect = contentRect;
  709.             growRect.left = growRect.right - 15;
  710.             growRect.top = growRect.bottom - 15;
  711.             
  712.             RgnHandle contentRgn = ODNewRgn();
  713.             RgnHandle growRgn = ODNewRgn();
  714.             RectRgn(contentRgn,&contentRect);
  715.             RectRgn(growRgn,&growRect);
  716.                     
  717.             if (_fIsResizable)
  718.             DiffRgn(contentRgn,growRgn,contentRgn);
  719.             ODDisposeHandle((Handle)growRgn);
  720.     
  721.             SetPort(_fPlatformWindow);
  722.             // InvalRgn(contentRgn);
  723.                     
  724.             ODShape* windowShape =_fRootFrame->CreateShape(ev);
  725.             windowShape->SetPlatformShape(ev,kODQuickDraw, (ODPlatformShape)contentRgn);
  726.     #ifdef TO_BE_DELETED
  727.             ODTransform* xform = _fRootFacet->AcquireExternalTransform(ev);
  728.             windowShape->InverseTransform(ev, xform);    // JBS - must transform frameShape to facet coords
  729.             ODReleaseObject(ev, xform);
  730.     #endif // TO_BE_DELETED
  731.             ODShape* tempShape = kODNULL;
  732.             tempShape = windowShape->Copy(ev);
  733.             _fRootFacet->GetFrame(ev)->ChangeFrameShape(ev, windowShape, kODNULL);
  734.             _fRootFacet->ChangeGeometry(ev, tempShape, kODNULL, kODNULL);
  735.             ODReleaseObject(ev, windowShape);
  736.             ODReleaseObject(ev, tempShape);
  737.         }
  738.         _fIsDirty = kODTrue;
  739.  
  740.     SOM_CATCH_ALL
  741.     SOM_ENDTRY
  742. }    // AdjustWindowShape
  743.  
  744.  
  745. //-------------------------------------------------------------------------------------
  746. // ODWindow: Open
  747. //
  748. // Description
  749. //-------------------------------------------------------------------------------------
  750.  
  751.  
  752. SOM_Scope void  SOMLINK ODWindowOpen (ODWindow *somSelf, Environment *ev)
  753. {
  754.     ODWindowData *somThis = ODWindowGetData(somSelf);
  755.     ODWindowMethodDebug("ODWindow","Open");
  756.     
  757.     SOM_TRY
  758.  
  759.         if (_fRootFacet == kODNULL)
  760.         {
  761.             somSelf->CreateRootFacet(ev);
  762.             if ( _fShouldAdjustOnOpen )
  763.                 somSelf->AdjustWindowShape(ev);
  764.             _fIsDirty = kODTrue;
  765.         }
  766.     
  767.     SOM_CATCH_ALL
  768.     SOM_ENDTRY
  769. }
  770.  
  771. //-------------------------------------------------------------------------------------
  772. // ODWindow: Close
  773. //
  774. // Description
  775. //-------------------------------------------------------------------------------------
  776.  
  777.  
  778. SOM_Scope void  SOMLINK ODWindowClose(ODWindow *somSelf, Environment *ev)
  779. {
  780.     ODWindowData *somThis = ODWindowGetData(somSelf);
  781.     ODWindowMethodDebug("ODWindow","Close");
  782.  
  783.     SOM_TRY
  784.     
  785.         somSelf->Hide(ev);
  786.         _fSession->GetWindowState(ev)->RemoveWindow(ev,somSelf);
  787.     
  788.         if ( _fRootFrame )
  789.         {
  790.             if ( _fRootFacet )
  791.             {
  792.                 _fRootFrame->FacetRemoved(ev,_fRootFacet);
  793.                 _fSession->GetDispatcher(ev)->InvalidateFacetUnderMouse(ev);
  794.                 
  795.                 ODCanvas* rootCanvas = _fRootFacet->GetCanvas(ev); // DMc - new
  796.                 ODDeleteObject(rootCanvas); // DMc - new
  797.                 ODDeleteObject(_fRootFacet);
  798.             }
  799.     
  800.             _fRootFrame->Close(ev);
  801.             _fRootFrame = kODNULL;
  802.         }
  803.         
  804.         ODReleaseObject(ev, _fSourceFrame);
  805.         _fIsDirty = kODTrue;
  806.         somSelf->Release(ev);
  807.  
  808.     SOM_CATCH_ALL
  809.     SOM_ENDTRY
  810.     
  811. }    // Close()
  812.  
  813. //-------------------------------------------------------------------------------------
  814. // ODWindow: CloseAndRemove
  815. //
  816. // Description
  817. //-------------------------------------------------------------------------------------
  818.  
  819.  
  820. SOM_Scope void  SOMLINK ODWindowCloseAndRemove(ODWindow *somSelf, Environment *ev)
  821. {
  822.     ODWindowData *somThis = ODWindowGetData(somSelf);
  823.     ODWindowMethodDebug("ODWindow","CloseAndRemove");
  824.     
  825.     SOM_TRY
  826.     
  827.         if (_fPlatformWindow)
  828.         {
  829.             somSelf->Hide(ev);
  830.             _fSession->GetWindowState(ev)->RemoveWindow(ev,somSelf);
  831.         
  832.             if ( _fRootFrame )
  833.             {
  834.                 if ( _fRootFacet )
  835.                 {
  836.                     _fRootFrame->FacetRemoved(ev,_fRootFacet);
  837.                     _fSession->GetDispatcher(ev)->InvalidateFacetUnderMouse(ev);
  838.                     
  839.                     ODCanvas* rootCanvas = _fRootFacet->GetCanvas(ev); // DMc - new
  840.                     ODDeleteObject(rootCanvas); // DMc - new
  841.                     ODDeleteObject(_fRootFacet);
  842.                 }
  843.         
  844.                 if (!HAS_WRITE_ACCESS(_fDraft->GetPermissions(ev)))
  845.                 {
  846.                     _fRootFrame->Close(ev);
  847.                     _fRootFrame = kODNULL;
  848.                 }
  849.                 else
  850.                 {
  851.                     _fRootFrame->Remove(ev);
  852.                     _fRootFrame = kODNULL;
  853.                 }
  854.             }
  855.             
  856.             ODReleaseObject(ev, _fSourceFrame);
  857.             somSelf->Release(ev);
  858.             _fIsDirty = kODTrue;
  859.         }
  860.  
  861.     SOM_CATCH_ALL
  862.     SOM_ENDTRY
  863.  
  864. }    
  865.  
  866.  
  867.  
  868. //-------------------------------------------------------------------------------------
  869. // ODWindow: HandleActivateEvent
  870. //
  871. // Description
  872. //-------------------------------------------------------------------------------------
  873.  
  874. static void ODDrawGrowIcon(ODPlatformWindow window)
  875. {
  876.     GrafPtr    savePort;
  877.         
  878.     GetPort(&savePort);
  879.     SetPort(window);
  880.     Rect r = window->portRect;
  881.     r.left = r.right  - 15;
  882.     r.top  = r.bottom - 15;
  883.     RgnHandle    oldClip = kODNULL; ODVolatile(oldClip);
  884.     
  885.     TRY
  886.         oldClip = ODNewRgn();
  887.  
  888.         GetClip(oldClip);
  889.         ClipRect(&r);
  890.         DrawGrowIcon(window);
  891.         SetClip(oldClip);
  892.         
  893.     CATCH_ALL
  894.         // Don't Reraise. Since this gets called when putting up
  895.         // the low memory alert calls DeactivateFrontWindows #1280629
  896.     ENDTRY
  897.         
  898.     ODDisposeHandle((Handle)oldClip);
  899.     SetPort(savePort);
  900. }
  901.  
  902. #if ODDebug
  903.  
  904. // Validate windows in the debug build:
  905. #define OD_VALIDATE_WINDOW(w) ValidateWindow(w)
  906. // Only one of the next two lines should be active
  907. #define OD_SLAM_WINDOWS
  908. //#undef OD_SLAM_WINDOWS
  909.  
  910. #else /* ODDebug */
  911.  
  912. // Currently, these settings are the same as the debug ones
  913. #define OD_VALIDATE_WINDOW(w) ValidateWindow(w)
  914. // Only one of the next two lines should be active
  915. #define OD_SLAM_WINDOWS
  916. //#undef OD_SLAM_WINDOWS
  917.  
  918. #endif /* ODDebug */
  919.  
  920. static void ValidateWindow( ODPlatformWindow newWindow )
  921. {
  922.     WindowPeek wp = (WindowPeek)newWindow;
  923.     static RgnHandle rgn = kODNULL;
  924.     
  925.     if ( rgn == kODNULL )
  926.         rgn = ODNewRgn();
  927.  
  928.     if ( wp->visible && wp->hilited )    // Test only visible, active windows
  929.     {
  930.         Rect titleBarRect = (**wp->strucRgn).rgnBBox;
  931.         titleBarRect.bottom = (**wp->contRgn).rgnBBox.top - 1;
  932.         short titleHeight = titleBarRect.bottom - titleBarRect.top;
  933.  
  934.         InsetRect( &titleBarRect, 4, 4 );
  935.         if ( !EmptyRect( &titleBarRect ))
  936.         {
  937.             RectRgn( rgn, &titleBarRect );
  938.             SectRgn( GetGrayRgn(), rgn, rgn );
  939.             if ( EmptyRgn( rgn ))
  940.             {
  941. #ifdef OD_SLAM_WINDOWS
  942.                 WARN( "This window's title bar is not on-screen. It will be moved." );
  943.                 MoveWindow( newWindow, 2, LMGetMBarHeight() + titleHeight + 2, false );
  944. #else
  945.                 WARN( "This window's title bar is not on-screen." );
  946. #endif
  947.             }
  948.             else
  949.                 SetRectRgn( rgn, 0, 0, 0, 0 );
  950.         }
  951.     }
  952.     // Note: The region is not disposed--it's static so we can use it
  953.     // next time instead of doing a relatively expensive allocation. We
  954.     // depend on the Process Manager to clean up when the process terminates.
  955. }
  956.  
  957. SOM_Scope void  SOMLINK ODWindowHandleActivateEvent (ODWindow *somSelf, Environment *ev,
  958.         ODEventData* theEvent)
  959. {
  960.     ODWindowData *somThis = ODWindowGetData(somSelf);
  961.     ODWindowMethodDebug("ODWindow","HandleActivateEvent");
  962.  
  963.     ODFrame* frame = kODNULL;
  964.     ODFacetIterator* t = kODNULL; ODVolatile(t);
  965.     
  966.     SOM_TRY
  967.         
  968.         _fIsActive = (theEvent->modifiers & activeFlag == 1);
  969.         
  970.         if ( _fIsActive )
  971.             OD_VALIDATE_WINDOW( (WindowPtr)theEvent->message );
  972.  
  973.         t = _fRootFacet->CreateFacetIterator(ev,
  974.                                 kODBottomUp, kODBackToFront);
  975.         
  976.         for (ODFacet* facet = t->First(ev); t->IsNotComplete(ev); facet = t->Next(ev))
  977.         {
  978.             if (facet)
  979.             {
  980.                 TRY{
  981.                     frame = facet->GetFrame(ev);
  982.                     TempODPart part = frame->AcquirePart(ev); // -- TÇ tempobj'd
  983.                     if ((ODPart*)part)
  984.                         part->HandleEvent(ev,theEvent, frame, facet, kODNULL);
  985.                 }CATCH_ALL{
  986.                     // ignore exception
  987.                 }ENDTRY
  988.             }
  989.         }
  990.         ODDeleteObject(t);
  991.         if (somSelf->IsResizable(ev))
  992.             ODDrawGrowIcon(_fPlatformWindow);
  993.  
  994.     SOM_CATCH_ALL
  995.     
  996.         ODDeleteObject(t);
  997.         
  998.     SOM_ENDTRY
  999. }
  1000.     
  1001. //-------------------------------------------------------------------------------------
  1002. // ODWindow: HandleUpdateEvent
  1003. //
  1004. // Description
  1005. //-------------------------------------------------------------------------------------
  1006.  
  1007. SOM_Scope void  SOMLINK ODWindowHandleUpdateEvent (ODWindow *somSelf, Environment *ev,
  1008.         ODEventData* theEvent)
  1009. {
  1010.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1011.     ODWindowMethodDebug("ODWindow","HandleUpdateEvent");
  1012.  
  1013.     ODUnused(theEvent);
  1014.     
  1015.     SOM_TRY
  1016.         somSelf->Update(ev);
  1017.     SOM_CATCH_ALL
  1018.     SOM_ENDTRY
  1019. }
  1020.  
  1021. //-------------------------------------------------------------------------------------
  1022. // ODWindow: Update
  1023. //
  1024. // Description
  1025. //-------------------------------------------------------------------------------------
  1026.  
  1027. SOM_Scope void  SOMLINK ODWindowUpdate(ODWindow *somSelf, Environment *ev)
  1028. {
  1029.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1030.     ODWindowMethodDebug("ODWindow","Update");
  1031.     
  1032.     SOM_TRY
  1033.  
  1034.         if (_fPlatformWindow)
  1035.         {
  1036.                 // #1248624 Failure handling should be further improved, but this should prevent 
  1037.                 // the infinite dialog problem
  1038.             TRY    
  1039.                 GrafPtr    savePort;
  1040.         
  1041.                 GetPort(&savePort);
  1042.                 somSelf->PrepareCanvas(ev);
  1043.                 
  1044.                 TempODFrame activeFrame 
  1045.                     = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev,_fSelectionFocus);
  1046.                 BeginUpdate(_fPlatformWindow);                    // this sets up the visRgn
  1047.                 
  1048.                 if (!EmptyRgn(_fPlatformWindow->visRgn))            // draw if updating needs to be done 
  1049.                 {
  1050.                     // Let the part decide
  1051.                     // EraseRgn (_fPlatformWindow->visRgn);
  1052.                     
  1053.                     {
  1054.                         ODFacet* rootFacet = _fRootFacet;
  1055.             
  1056.                         RgnHandle updateRgn = ODNewRgn();
  1057.                         CopyRgn(_fPlatformWindow->visRgn, updateRgn);
  1058.                         TempODShape updateShape = rootFacet->CreateShape(ev);
  1059.                         updateShape->SetPlatformShape(ev,kODQuickDraw, updateRgn);
  1060.                         TempODTransform xform = rootFacet->AcquireWindowFrameTransform(ev, kODNULL);
  1061.                         updateShape->InverseTransform(ev, xform);
  1062.                         rootFacet->Update(ev, updateShape, kODNULL);
  1063.                     }
  1064.                     // • Focus back on the window so that everything gets reset
  1065.                     somSelf->PrepareCanvas(ev);
  1066.         
  1067.                     // • After everything is back in shape we need to get the grow icon drawn
  1068.                     if (somSelf->IsResizable(ev))
  1069.                         ODDrawGrowIcon(_fPlatformWindow);
  1070.                 }
  1071.                 EndUpdate(_fPlatformWindow);
  1072.                 somSelf->DrawActiveBorder(ev,activeFrame);
  1073.                 SetPort(savePort);
  1074.                 
  1075.             CATCH_ALL
  1076.                 EndUpdate(_fPlatformWindow);
  1077.             ENDTRY
  1078.         }    
  1079.         _fIsDirty = kODTrue;
  1080.     
  1081.     SOM_CATCH_ALL
  1082.     SOM_ENDTRY
  1083. }    //  SOMLINK ODWindowUpdate
  1084.  
  1085. //-------------------------------------------------------------------------------------
  1086. // ODWindow: DrawActiveBorder
  1087. //
  1088. // Description
  1089. //-------------------------------------------------------------------------------------
  1090.  
  1091. SOM_Scope void  SOMLINK ODWindowDrawActiveBorder(ODWindow *somSelf, Environment *ev, ODFrame* frame)
  1092. {
  1093.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1094.     ODWindowMethodDebug("ODWindow","DrawActiveBorder");
  1095.  
  1096. // !!! needs to draw border for all facets of active frame
  1097. // Don't draw in background. Also need to invalidate
  1098.  
  1099.     SOM_TRY
  1100.  
  1101.         if ( !_fInBackground && frame && (frame != _fRootFrame) )
  1102.         {
  1103.             frame->DrawActiveBorder(ev);
  1104.         }
  1105.         
  1106.     SOM_CATCH_ALL
  1107.     SOM_ENDTRY
  1108. }
  1109.  
  1110. //-------------------------------------------------------------------------------------
  1111. // ODWindow: PrepareCanvas
  1112. //
  1113. // Description
  1114. //-------------------------------------------------------------------------------------
  1115.  
  1116. SOM_Scope void  SOMLINK ODWindowPrepareCanvas(ODWindow *somSelf, Environment *ev)
  1117. {
  1118.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1119.     ODWindowMethodDebug("ODWindow","PrepareCanvas");
  1120.     
  1121.     SOM_TRY
  1122.  
  1123.         if (_fPlatformWindow)
  1124.         {
  1125.             SetPort (_fPlatformWindow);
  1126.             SetOrigin(0,0);
  1127.             ClipRect (&_fPlatformWindow->portRect);
  1128.         }
  1129.         else
  1130.             ClipRect (&ODQDGlobals.thePort->portRect);
  1131.  
  1132.     SOM_CATCH_ALL
  1133.     SOM_ENDTRY
  1134. }
  1135.  
  1136. //-------------------------------------------------------------------------------------
  1137. // ODWindow: IsResizable
  1138. //
  1139. // Description
  1140. //-------------------------------------------------------------------------------------
  1141.  
  1142. SOM_Scope ODBoolean  SOMLINK ODWindowIsResizable(ODWindow *somSelf, Environment *ev)
  1143. {
  1144.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1145.     ODWindowMethodDebug("ODWindow","IsResizable");
  1146.  
  1147.     return _fIsResizable;
  1148. }
  1149.  
  1150. //-------------------------------------------------------------------------------------
  1151. // ODWindow: IsFloating
  1152. //
  1153. // Description
  1154. //-------------------------------------------------------------------------------------
  1155.  
  1156. SOM_Scope ODBoolean  SOMLINK ODWindowIsFloating(ODWindow *somSelf, Environment *ev)
  1157. {
  1158.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1159.     ODWindowMethodDebug("ODWindow","IsFloating");
  1160.  
  1161.     return _fIsFloating;
  1162. }
  1163.  
  1164. //-------------------------------------------------------------------------------------
  1165. // ODWindow: IsRootWindow
  1166. //
  1167. // Description
  1168. //-------------------------------------------------------------------------------------
  1169.  
  1170. SOM_Scope ODBoolean  SOMLINK ODWindowIsRootWindow(ODWindow *somSelf, Environment *ev)
  1171. {
  1172.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1173.     ODWindowMethodDebug("ODWindow","IsRootWindow");
  1174.  
  1175.     return _fIsRootWindow;
  1176. }
  1177.  
  1178. //-------------------------------------------------------------------------------------
  1179. // ODWindow: ShouldSave
  1180. //
  1181. // Description
  1182. //-------------------------------------------------------------------------------------
  1183.  
  1184. SOM_Scope ODBoolean  SOMLINK ODWindowShouldSave(ODWindow *somSelf, Environment *ev)
  1185. {
  1186.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1187.     ODWindowMethodDebug("ODWindow","ShouldSave");
  1188.  
  1189.     return _fShouldSave;
  1190. }
  1191.  
  1192. //-------------------------------------------------------------------------------------
  1193. // ODWindow: SetShouldSave
  1194. //
  1195. // Description
  1196. //-------------------------------------------------------------------------------------
  1197.  
  1198. SOM_Scope void  SOMLINK ODWindowSetShouldSave(ODWindow *somSelf, Environment *ev,
  1199.         ODBoolean shouldSave)
  1200. {
  1201.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1202.     ODWindowMethodDebug("ODWindow","SetShouldSave");
  1203.  
  1204.     _fShouldSave = shouldSave;
  1205.     _fIsDirty = kODTrue;
  1206. }
  1207.  
  1208. //-------------------------------------------------------------------------------------
  1209. // ODWindow: ShouldShowLinks
  1210. //
  1211. // Description
  1212. //-------------------------------------------------------------------------------------
  1213.  
  1214. SOM_Scope ODBoolean  SOMLINK ODWindowShouldShowLinks(ODWindow *somSelf, Environment *ev)
  1215. {
  1216.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1217.     ODWindowMethodDebug("ODWindow","ShouldShowLinks");
  1218.  
  1219.     return _fShouldShowLinks;
  1220. }
  1221.  
  1222. //-------------------------------------------------------------------------------------
  1223. // ODWindow: SetShouldShowLinks
  1224. //
  1225. // Description
  1226. //-------------------------------------------------------------------------------------
  1227.  
  1228. SOM_Scope void  SOMLINK ODWindowSetShouldShowLinks(ODWindow *somSelf, Environment *ev,
  1229.         ODBoolean shouldShowLinks)
  1230. {
  1231.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1232.     ODWindowMethodDebug("ODWindow","SetShouldShowLinks");
  1233.  
  1234.     _fShouldShowLinks = shouldShowLinks;
  1235.     _fIsDirty = kODTrue;
  1236. }
  1237.  
  1238. //-------------------------------------------------------------------------------------
  1239. // ODWindow: ShouldDispose
  1240. //
  1241. // Description
  1242. //-------------------------------------------------------------------------------------
  1243.  
  1244. SOM_Scope ODBoolean  SOMLINK ODWindowShouldDispose(ODWindow *somSelf, Environment *ev)
  1245. {
  1246.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1247.     ODWindowMethodDebug("ODWindow","ShouldDispose");
  1248.  
  1249.     return _fShouldDispose;
  1250. }
  1251.  
  1252. //-------------------------------------------------------------------------------------
  1253. // ODWindow: GetFacetUnderPoint
  1254. //
  1255. // Description
  1256. //-------------------------------------------------------------------------------------
  1257.  
  1258. typedef enum { kODForDragEvent, kODForMouseEvent } FacetSearchConstraint;
  1259.  
  1260. ODFacet* GetFacetUnderPointInternal( Environment *ev, ODFacet* rootFacet,
  1261.         ODPoint* windowPoint, FacetSearchConstraint constraint );
  1262.  
  1263.  
  1264. //-------------------------------------------------------------------------------------
  1265. // ODWindow: GetFacetUnderPoint
  1266. //
  1267. // Description
  1268. //-------------------------------------------------------------------------------------
  1269.  
  1270. SOM_Scope ODFacet*  SOMLINK ODWindowGetFacetUnderPointForDrag(ODWindow *somSelf,
  1271.         Environment *ev, ODPoint* windowPoint)
  1272. {
  1273.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1274.     ODWindowMethodDebug("ODWindow","GetFacetUnderPointForDrag");
  1275.  
  1276.     ODFacet* foundFacet = kODNULL;
  1277.     
  1278.     SOM_TRY
  1279.         foundFacet = GetFacetUnderPointInternal( ev, _fRootFacet, windowPoint,
  1280.                 kODForDragEvent );
  1281.     SOM_CATCH_ALL
  1282.     SOM_ENDTRY
  1283.  
  1284.     return foundFacet;
  1285. }
  1286.  
  1287. //-------------------------------------------------------------------------------------
  1288. // ODWindow: GetFacetUnderPoint
  1289. //
  1290. // Description
  1291. //-------------------------------------------------------------------------------------
  1292.  
  1293. SOM_Scope ODFacet*  SOMLINK ODWindowGetFacetUnderPoint(ODWindow *somSelf,
  1294.         Environment *ev, ODPoint* windowPoint)
  1295. {
  1296.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1297.     ODWindowMethodDebug("ODWindow","GetFacetUnderPoint");
  1298.  
  1299.     ODFacet* foundFacet = kODNULL;
  1300.     
  1301.     SOM_TRY
  1302.         foundFacet = GetFacetUnderPointInternal( ev, _fRootFacet, windowPoint,
  1303.                 kODForMouseEvent );
  1304.     SOM_CATCH_ALL
  1305.     SOM_ENDTRY
  1306.  
  1307.     return foundFacet;
  1308. }
  1309.  
  1310. //-------------------------------------------------------------------------------------
  1311. // GetFacetUnderPointInternal
  1312. //
  1313. // Description
  1314. // Utility function for the two GetFacetUnderPoint methods above.
  1315. //-------------------------------------------------------------------------------------
  1316. ODFacet* GetFacetUnderPointInternal( Environment *ev, ODFacet* rootFacet,
  1317.         ODPoint* windowPoint, FacetSearchConstraint constraint )
  1318. {
  1319.     ODFacet* foundFacet = kODNULL;
  1320.     ODFacetIterator* t = kODNULL;        ODVolatile(t);
  1321.     ODPoint framePoint;
  1322.  
  1323.     SOM_TRY
  1324.         //!!! Should use frameshape containment to prune search
  1325.         t = rootFacet->CreateFacetIterator(ev,
  1326.                                 kODTopDown, kODBackToFront);
  1327.     
  1328.         for ( ODFacet* facet = t->First(ev);
  1329.                 t->IsNotComplete(ev);
  1330.                 facet = t->Next(ev) )
  1331.         {
  1332.             // get windowPoint in frame coords for hit-testing
  1333.             { TempODTransform winToFrame = facet->AcquireWindowFrameTransform(ev, kODNULL);
  1334.               framePoint = *windowPoint;
  1335.               winToFrame->InvertPoint(ev, &framePoint);
  1336.             }
  1337.             
  1338.             if (facet->ContainsPoint(ev, &framePoint, kODNULL))
  1339.             {
  1340.                 foundFacet = facet;
  1341. #if 0            /* this is the old code */
  1342.                 if (facet->GetFrame(ev)->IsFrozen(ev) || facet->IsSelected(ev))        
  1343.                     t->SkipChildren(ev);
  1344. #else            /* this is the new -- replaces above */
  1345.                 if (facet->GetFrame(ev)->IsFrozen(ev))
  1346.                     t->SkipChildren(ev);
  1347.                 else if ( (constraint == kODForMouseEvent) && facet->IsSelected(ev))
  1348.                 {
  1349.                     t->SkipChildren(ev);
  1350.                 }
  1351. #endif
  1352.             }
  1353.             else
  1354.                 t->SkipChildren(ev);
  1355.         }
  1356.         delete t;
  1357.  
  1358.     SOM_CATCH_ALL
  1359.  
  1360.         ODDeleteObject(t);
  1361.  
  1362.     SOM_ENDTRY
  1363.  
  1364.     return foundFacet;
  1365. }
  1366.  
  1367. //-------------------------------------------------------------------------------------
  1368. // ODWindow: IsActive
  1369. //
  1370. // Description
  1371. //-------------------------------------------------------------------------------------
  1372.  
  1373. SOM_Scope ODBoolean  SOMLINK ODWindowIsActive(ODWindow *somSelf, Environment *ev)
  1374. {
  1375.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1376.     ODWindowMethodDebug("ODWindow","IsActive");
  1377.     
  1378.     ODBoolean isActive = _fIsActive && !_fInBackground;
  1379.  
  1380.     return isActive;
  1381. }
  1382.  
  1383. //-------------------------------------------------------------------------------------
  1384. // ODWindow: Show
  1385. //
  1386. // Description
  1387. //-------------------------------------------------------------------------------------
  1388.  
  1389. SOM_Scope void  SOMLINK ODWindowShow(ODWindow *somSelf, Environment *ev)
  1390. {
  1391.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1392.     ODWindowMethodDebug("ODWindow","Show");
  1393.     
  1394.     SOM_TRY
  1395.  
  1396.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1397.         
  1398.         if (!somSelf->IsShown(ev))    
  1399.             _fSession->GetWindowState(ev)->ShowODWindow(ev,somSelf);
  1400.         _fIsDirty = kODTrue;
  1401.  
  1402.     SOM_CATCH_ALL
  1403.     SOM_ENDTRY
  1404. }
  1405.     
  1406. //-------------------------------------------------------------------------------------
  1407. // ODWindow: Hide
  1408. //
  1409. // Description
  1410. //-------------------------------------------------------------------------------------
  1411.  
  1412. SOM_Scope void  SOMLINK ODWindowHide(ODWindow *somSelf, Environment *ev)
  1413. {
  1414.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1415.     ODWindowMethodDebug("ODWindow","Hide");
  1416.  
  1417.     SOM_TRY
  1418.  
  1419.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1420.  
  1421.         if (somSelf->IsShown(ev))
  1422.         {
  1423.             _fSession->GetWindowState(ev)->HideODWindow(ev,somSelf);
  1424.             _fIsDirty = kODTrue;
  1425.         }
  1426.  
  1427.     SOM_CATCH_ALL
  1428.     SOM_ENDTRY
  1429. }
  1430.  
  1431. //-------------------------------------------------------------------------------------
  1432. // ODWindow: SuspendResume
  1433. //
  1434. // Send event to each visible window
  1435. //-------------------------------------------------------------------------------------
  1436.  
  1437. SOM_Scope void  SOMLINK ODWindowSuspendResume(ODWindow *somSelf, Environment *ev,
  1438.         ODEventData* event)
  1439. {
  1440.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1441.     ODWindowMethodDebug("ODWindow","SuspendResume");
  1442.  
  1443.  
  1444.     const short kResumeMask = 0x01;    // High byte suspend/resume event 
  1445.     ODFrame* frame = kODNULL;
  1446.     ODFacetIterator* t = kODNULL; ODVolatile(t);
  1447.  
  1448.     _fInBackground = (event->message & kResumeMask) == 0;
  1449.  
  1450.     SOM_TRY
  1451.  
  1452.         somSelf->PrepareCanvas(ev);
  1453.         if (somSelf->IsResizable(ev))
  1454.             ODDrawGrowIcon(_fPlatformWindow);
  1455.     
  1456.         t = _fRootFacet->CreateFacetIterator(ev,
  1457.                                 kODTopDown, kODFrontToBack);
  1458.         
  1459.         for (ODFacet* facet = t->First(ev); t->IsNotComplete(ev); facet = t->Next(ev))
  1460.         {
  1461.             if (facet)
  1462.             {
  1463.                 TRY{
  1464.                     frame = facet->GetFrame(ev);
  1465.                     TempODPart part = frame->AcquirePart(ev); // -- TÇ tempobj'd
  1466.                     if ((ODPart*)part)
  1467.                         part->HandleEvent(ev,event, frame, facet, kODNULL);
  1468.                 }CATCH_ALL{
  1469.                     // ignore exception
  1470.                 }ENDTRY
  1471.             }
  1472.         }
  1473.         ODDeleteObject(t);
  1474.  
  1475.         
  1476.         TempODFrame activeFrame = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev,_fSelectionFocus);
  1477.         if (activeFrame)
  1478.         {
  1479.             if (_fInBackground)
  1480.                 activeFrame->InvalidateActiveBorder(ev);
  1481.             else    // Limitation of API: Can't call Invalidate twice, because shape gets released
  1482.                 activeFrame->DrawActiveBorder(ev);
  1483.         }
  1484.         
  1485.  
  1486.  
  1487.     SOM_CATCH_ALL
  1488.     
  1489.         ODDeleteObject(t);
  1490.         
  1491.     SOM_ENDTRY
  1492. }
  1493.  
  1494. //-------------------------------------------------------------------------------------
  1495. // ODWindow: Activate
  1496. //
  1497. // Description
  1498. //-------------------------------------------------------------------------------------
  1499.  
  1500. SOM_Scope void  SOMLINK ODWindowActivate(ODWindow *somSelf, Environment *ev)
  1501. {
  1502.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1503.     ODWindowMethodDebug("ODWindow","Activate");
  1504.  
  1505.     SOM_TRY
  1506.     
  1507.         // Floating window implementation relies on suppressing activate events
  1508.         // Part::HandleEvent expects them, so they're synthesize here.
  1509.         // They must be routed through the dispatcher, so they can be monitored/patched
  1510.         // The modifiers field is hacked to alert the dispatcher that this is
  1511.         // an OpenDoc-generated activate event.
  1512.     
  1513.         EventRecord event;
  1514.  
  1515.         SetActivateEvent(event, _fPlatformWindow, kODTrue);
  1516.                 
  1517.         _fSession->GetDispatcher(ev)->Dispatch(ev, &event);
  1518.  
  1519.     SOM_CATCH_ALL
  1520.     SOM_ENDTRY
  1521. }
  1522.  
  1523. //-------------------------------------------------------------------------------------
  1524. // ODWindow: Deactivate
  1525. //
  1526. // Description
  1527. //-------------------------------------------------------------------------------------
  1528.  
  1529. SOM_Scope void  SOMLINK ODWindowDeactivate(ODWindow *somSelf, Environment *ev)
  1530. {
  1531.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1532.     ODWindowMethodDebug("ODWindow","Deactivate");
  1533.  
  1534.     SOM_TRY
  1535.     
  1536.         // Floating window implementation relies on suppressing activate events
  1537.         // Part::HandleEvent expects them, so they're synthesize here.
  1538.         // They must be routed through the dispatcher, so they can be monitored/patched
  1539.         // Bit 1 (starting from 0) of the modifiers field is set to alert the dispatcher 
  1540.         // that this is an OpenDoc-generated activate event.
  1541.  
  1542.         EventRecord event;
  1543.         
  1544.         SetActivateEvent(event, _fPlatformWindow, kODFalse);
  1545.                 
  1546.         _fSession->GetDispatcher(ev)->Dispatch(ev, &event);
  1547.  
  1548.     SOM_CATCH_ALL
  1549.     SOM_ENDTRY
  1550. }
  1551.  
  1552. //-------------------------------------------------------------------------------------
  1553. // ODWindow: Drag
  1554. //
  1555. // Description
  1556. //-------------------------------------------------------------------------------------
  1557.  
  1558. SOM_Scope void  SOMLINK ODWindowDrag(ODWindow *somSelf, Environment *ev,
  1559.         Point* startPoint,
  1560.         Rect* draggingBounds)
  1561. {
  1562.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1563.     ODWindowMethodDebug("ODWindow","Drag");
  1564.  
  1565.     SOM_TRY
  1566.  
  1567.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1568.         
  1569.         _fSession->GetWindowState(ev)->DragODWindow(ev,somSelf, startPoint, draggingBounds);
  1570.  
  1571.     SOM_CATCH_ALL
  1572.     SOM_ENDTRY
  1573. }
  1574.  
  1575. //-------------------------------------------------------------------------------------
  1576. // ODWindow: Select
  1577. //
  1578. // Description
  1579. //-------------------------------------------------------------------------------------
  1580.  
  1581. SOM_Scope void  SOMLINK ODWindowSelect(ODWindow *somSelf, Environment *ev)
  1582. {
  1583.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1584.     ODWindowMethodDebug("ODWindow","Select");
  1585.  
  1586.     SOM_TRY
  1587.  
  1588.         if (_fInBackground)
  1589.         {
  1590.             ProcessSerialNumber current;
  1591.             OSErr    err = GetCurrentProcess(¤t);
  1592.             if (err == noErr)
  1593.                 SetFrontProcess(¤t);
  1594.         }    
  1595.         _fSession->GetWindowState(ev)->SelectODWindow(ev,somSelf);
  1596.  
  1597.     SOM_CATCH_ALL
  1598.     SOM_ENDTRY
  1599. }
  1600.  
  1601. //-------------------------------------------------------------------------------------
  1602. // ODWindow: IsShown
  1603. //
  1604. // Description
  1605. //-------------------------------------------------------------------------------------
  1606.  
  1607. SOM_Scope ODBoolean  SOMLINK ODWindowIsShown(ODWindow *somSelf, Environment *ev)
  1608. {
  1609.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1610.     ODWindowMethodDebug("ODWindow","IsShown");
  1611.     
  1612.     ODBoolean isShown = kODFalse;
  1613.     
  1614.     SOM_TRY
  1615.  
  1616.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1617.         
  1618.         isShown = ((WindowRecord*)_fPlatformWindow)->visible;
  1619.  
  1620.     SOM_CATCH_ALL
  1621.     SOM_ENDTRY
  1622.     
  1623.     return isShown;
  1624. }
  1625.  
  1626. //-------------------------------------------------------------------------------------
  1627. // Protected methods
  1628. //
  1629. // Description
  1630. //-------------------------------------------------------------------------------------
  1631.  
  1632. SOM_Scope ODBoolean  SOMLINK ODWindowHasCloseBox(ODWindow *somSelf, Environment *ev)
  1633. {
  1634.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1635.     ODWindowMethodDebug("ODWindow","HasCloseBox");
  1636.  
  1637.     ODBoolean hasCloseBox = kODFalse;
  1638.     
  1639.     SOM_TRY
  1640.  
  1641.         ASSERT(_fPlatformWindow != kODNULL,kODErrInvalidPlatformWindow);
  1642.         hasCloseBox =     ((WindowRecord*)_fPlatformWindow)->goAwayFlag;
  1643.  
  1644.     SOM_CATCH_ALL
  1645.     SOM_ENDTRY
  1646.     
  1647.     return hasCloseBox;
  1648. }
  1649.     
  1650. SOM_Scope ODBoolean  SOMLINK ODWindowHasZoomBox(ODWindow *somSelf, Environment *ev)
  1651.  
  1652. {
  1653.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1654.     ODWindowMethodDebug("ODWindow","HasZoomBox");
  1655.  
  1656.     ODBoolean hasZoomBox = kODFalse;
  1657.     
  1658.     SOM_TRY
  1659.     
  1660.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1661.         hasZoomBox = ((WindowRecord*)_fPlatformWindow)->spareFlag;
  1662.  
  1663.     SOM_CATCH_ALL
  1664.     SOM_ENDTRY
  1665.     
  1666.     return hasZoomBox;
  1667. }
  1668.  
  1669. SOM_Scope ODBoolean  SOMLINK ODWindowHasGrowBox(ODWindow *somSelf, Environment *ev)
  1670. {
  1671.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1672.     ODWindowMethodDebug("ODWindow","HasGrowBox");
  1673.  
  1674.     ODBoolean hasGrowBox = kODFalse;
  1675.     
  1676.     SOM_TRY
  1677.  
  1678.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1679.         hasGrowBox = somSelf->IsResizable(ev); 
  1680.  
  1681.     SOM_CATCH_ALL
  1682.     SOM_ENDTRY
  1683.     
  1684.     return hasGrowBox;
  1685. }
  1686.  
  1687. SOM_Scope ODSShort  SOMLINK ODWindowGetProcID(ODWindow *somSelf, Environment *ev)
  1688. {
  1689.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1690.     ODWindowMethodDebug("ODWindow","GetProcID");
  1691.     
  1692.     short theID = 0; 
  1693.     ResType theType;
  1694.     Str255 theName;
  1695.  
  1696.     SOM_TRY
  1697.     
  1698.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1699.  
  1700.         GetResInfo(((WindowPeek)_fPlatformWindow)->windowDefProc, &theID, &theType, theName);
  1701.         short theVariant = GetWVariant(_fPlatformWindow);
  1702.         theID = theID*16 + theVariant;
  1703.         // return GetWVariant(_fPlatformWindow);
  1704.         
  1705.     SOM_CATCH_ALL
  1706.     SOM_ENDTRY
  1707.     
  1708.     return theID;
  1709.     
  1710. }
  1711.  
  1712. SOM_Scope void  SOMLINK ODWindowGetWindowBounds(ODWindow *somSelf, Environment *ev,
  1713.         Rect* bounds)
  1714. {
  1715.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1716.     ODWindowMethodDebug("ODWindow","GetWindowBounds");
  1717.     
  1718.     SOM_TRY
  1719.  
  1720.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1721.  
  1722.     // This old code doesn't work when the window is shaded by WindowShade:
  1723.         
  1724.         //ODRgnHandle contRgn;
  1725.         
  1726.         //contRgn = ((WindowRecord*)_fPlatformWindow)->contRgn;
  1727.         //*bounds = (**contRgn).rgnBBox;
  1728.     
  1729.     // This new code works with WindowShade:
  1730.         
  1731.         const ODUShort kColorPort = 0xC000;
  1732.          ODBoolean isCGrafPort =
  1733.              (((CGrafPtr)_fPlatformWindow)->portVersion & kColorPort ) == kColorPort;
  1734.  
  1735.         if ( isCGrafPort )
  1736.         {
  1737.             CGrafPtr port = (CGrafPtr)_fPlatformWindow;
  1738.             bounds->left   = port->portRect.left - (**(port->portPixMap)).bounds.left;
  1739.             bounds->top    = port->portRect.top - (**(port->portPixMap)).bounds.top;
  1740.             bounds->right  = bounds->left - port->portRect.left + port->portRect.right;
  1741.             bounds->bottom = bounds->top - port->portRect.top + port->portRect.bottom;
  1742.         }
  1743.         else // It's just a GrafPort
  1744.         {
  1745.             GrafPtr port = (GrafPtr)_fPlatformWindow;
  1746.             bounds->left   = port->portRect.left - port->portBits.bounds.left;
  1747.             bounds->top    = port->portRect.top - port->portBits.bounds.top;
  1748.             bounds->right  = bounds->left - port->portRect.left + port->portRect.right;
  1749.             bounds->bottom = bounds->top - port->portRect.top + port->portRect.bottom;
  1750.         }
  1751.         
  1752.     SOM_CATCH_ALL
  1753.     SOM_ENDTRY    
  1754. }
  1755.  
  1756. SOM_Scope ODSLong  SOMLINK ODWindowGetRefCon(ODWindow *somSelf, Environment *ev)
  1757. {
  1758.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1759.     ODWindowMethodDebug("ODWindow","GetRefCon");
  1760.     
  1761.     ODSLong refCon = 0;
  1762.     
  1763.     SOM_TRY
  1764.  
  1765.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1766.         refCon = ((WindowRecord*)_fPlatformWindow)->refCon;
  1767.  
  1768.     SOM_CATCH_ALL
  1769.     SOM_ENDTRY    
  1770.     
  1771.     return refCon;
  1772. }
  1773.  
  1774. //-------------------------------------------------------------------------------------
  1775. // ODWindow: SetWindowTitle
  1776. //
  1777. // Description
  1778. //-------------------------------------------------------------------------------------
  1779.  
  1780. SOM_Scope void  SOMLINK ODWindowSetWindowTitle(ODWindow *somSelf, Environment *ev,
  1781.         char* title)
  1782. {
  1783.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1784.     ODWindowMethodDebug("ODWindow","SetWindowTitle");
  1785.     
  1786.     Str255 titleCopy;
  1787.     
  1788.     strcpy( (char*) &(titleCopy[1]), title);
  1789.     titleCopy[0] = strlen(title);
  1790.     
  1791.     SOM_TRY
  1792.  
  1793.         SetWTitle(_fPlatformWindow, titleCopy);
  1794.         _fIsDirty = kODTrue;
  1795.  
  1796.     SOM_CATCH_ALL
  1797.     SOM_ENDTRY    
  1798. }
  1799.  
  1800. //-------------------------------------------------------------------------------------
  1801. // ODWindow: SetWasVisible
  1802. //
  1803. // Description
  1804. //-------------------------------------------------------------------------------------
  1805.  
  1806. SOM_Scope void  SOMLINK ODWindowSetWasVisible(ODWindow *somSelf, Environment *ev,
  1807.         ODBoolean wasVisible)
  1808. {
  1809.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1810.     ODWindowMethodDebug("ODWindow","SetWasVisible");
  1811.  
  1812.     _fWasVisible = wasVisible;
  1813.     _fIsDirty = kODTrue;
  1814. }
  1815.  
  1816. //-------------------------------------------------------------------------------------
  1817. // ODWindow: GetWasVisible
  1818. //
  1819. // Description
  1820. //-------------------------------------------------------------------------------------
  1821.  
  1822. SOM_Scope ODBoolean  SOMLINK ODWindowGetWasVisible(ODWindow *somSelf, Environment *ev)
  1823. {
  1824.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1825.     ODWindowMethodDebug("ODWindow","GetWasVisible");
  1826.  
  1827.     return _fWasVisible;
  1828. }
  1829.  
  1830. //-------------------------------------------------------------------------------------
  1831. // ODWindow: Externalize
  1832. //
  1833. // Description
  1834. //-------------------------------------------------------------------------------------
  1835.  
  1836. SOM_Scope void  SOMLINK ODWindowExternalize(ODWindow *somSelf, Environment *ev)
  1837. {
  1838.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1839.     ODWindowMethodDebug("ODWindow","Externalize");
  1840.  
  1841.     // #1246478 Removing fIsDirty optimization, because clients can call GetPlatformWindow
  1842.     // and change things. 
  1843.     //if ( !_fIsDirty )
  1844.     //    return;
  1845.         
  1846.     SOM_TRY
  1847.  
  1848.     // Should Title be an ODIText?
  1849.         
  1850.         ODStorageUnit* su = _fStorageUnit;
  1851.         
  1852.         // No need to do these ASSERTs because the StdTypIO routines make sure
  1853.         // the appropriate property and value exist. -TÇ
  1854.         /*
  1855.         ASSERT(su->Exists(ev,kODPropWindowRect, kODRect, 0), kODErrInvalidWindow);        
  1856.         ASSERT(su->Exists(ev,kODPropWindowTitle, kODMacIText, 0), kODErrInvalidWindow);
  1857.         ASSERT(su->Exists(ev,kODPropWindowProcID, kODSShort, 0), kODErrInvalidWindow);
  1858.         ASSERT(su->Exists(ev,kODPropWindowIsVisible, kODBoolean, 0), kODErrInvalidWindow);
  1859.         ASSERT(su->Exists(ev,kODPropWindowHasCloseBox, kODBoolean, 0), kODErrInvalidWindow);
  1860.         ASSERT(su->Exists(ev,kODPropWindowHasZoomBox, kODBoolean, 0), kODErrInvalidWindow);
  1861.         ASSERT(su->Exists(ev,kODPropWindowIsResizable, kODBoolean, 0), kODErrInvalidWindow);
  1862.         ASSERT(su->Exists(ev,kODPropWindowIsRootWindow, kODBoolean, 0), kODErrInvalidWindow);
  1863.         ASSERT(su->Exists(ev,kODPropWindowIsFloating, kODBoolean, 0), kODErrInvalidWindow);
  1864.         ASSERT(su->Exists(ev,kODPropWindowRefCon, kODSLong, 0), kODErrInvalidWindow);
  1865.         ASSERT(su->Exists(ev,kODPropRootFrame, kODStrongStorageUnitRef, 0), kODErrInvalidWindow);
  1866.         //ASSERT(su->Exists(ev,kODPropSourceFrame, kODStrongStorageUnitRef, 0), kODErrInvalidWindow);
  1867.         ASSERT(su->Exists(ev,kODPropShouldShowLinks, kODBoolean, 0), kODErrInvalidWindow);
  1868.         */
  1869.         
  1870.         // Externalize Window Manager properties
  1871.     
  1872.         // Externalize the bounds as a standard ODRect
  1873.     
  1874.         Rect r;
  1875.         somSelf->GetWindowBounds(ev,&r);
  1876.         ODRect odRect(r);
  1877.         ODSetRectProp(ev, su, kODPropWindowRect, kODRect, &odRect);
  1878.         
  1879.         // Externalize title as an IText
  1880.         
  1881.         Str255 title;
  1882.         GetWTitle(_fPlatformWindow, title);
  1883.         
  1884.         ODScriptCode script = FontToScript(GetAppFont());
  1885.         ODLangCode lang = GetScriptVariable(script, smScriptLang);
  1886.  
  1887.         ODIText* iText = CreateITextPString(script, lang, &title[0]);
  1888.         ODSetITextProp(ev, su, kODPropWindowTitle, kODMacIText, iText);
  1889.         DisposeIText(iText);
  1890.     
  1891.         ODSetSShortProp(ev, su, kODPropWindowProcID, kODSShort, somSelf->GetProcID(ev));
  1892.         ODSetBooleanProp(ev, su, kODPropWindowIsVisible, kODBoolean, somSelf->IsShown(ev));
  1893.         ODSetBooleanProp(ev, su, kODPropWindowHasCloseBox, kODBoolean,  somSelf->HasCloseBox(ev));
  1894.         ODSetBooleanProp(ev, su, kODPropWindowHasZoomBox, kODBoolean,  somSelf->HasZoomBox(ev));
  1895.         ODSetULongProp(ev, su, kODPropWindowRefCon, kODSLong, somSelf->GetRefCon(ev));
  1896.         
  1897.         // Other properties
  1898.         
  1899.         ODSetBooleanProp(ev, su, kODPropWindowIsResizable, kODBoolean,   somSelf->IsResizable(ev));
  1900.         ODSetBooleanProp(ev, su, kODPropWindowIsFloating, kODBoolean, somSelf->IsFloating(ev));
  1901.         ODSetBooleanProp(ev, su, kODPropWindowIsRootWindow, kODBoolean, somSelf->IsRootWindow(ev));
  1902.     
  1903.         ODSetBooleanProp(ev, su, kODPropShouldShowLinks, kODBoolean, somSelf->ShouldShowLinks(ev)); 
  1904.     
  1905.         // root frame
  1906.     
  1907.         ODSetStrongSURefProp(ev, su, kODPropRootFrame, kODStrongStorageUnitRef, _fRootFrame->GetStorageUnit(ev)->GetID(ev));
  1908.     
  1909.         // Source Frame (this property is only written if the value is non-NULL)  
  1910.             
  1911.         if (_fSourceFrame)
  1912.         {            
  1913.             ODSetStrongSURefProp(ev, su, kODPropSourceFrame, kODStrongStorageUnitRef, 
  1914.                             _fSourceFrame->GetStorageUnit(ev)->GetID(ev));
  1915.         }
  1916.         else if (ODSUExistsThenFocus(ev, su ,kODPropSourceFrame, kODStrongStorageUnitRef))
  1917.         {
  1918.             su->Remove(ev);
  1919.         }
  1920.         
  1921.         // Annotate the root frame with the window properties
  1922.         ODStorageUnit* frameSU = _fRootFrame->GetStorageUnit(ev);
  1923.         ODSetStrongSURefProp(ev, frameSU, kODPropWindowProperties, kODStrongStorageUnitRef, 
  1924.                         su->GetID(ev));
  1925.     
  1926.         _fIsDirty = kODFalse;
  1927.         
  1928.     SOM_CATCH_ALL
  1929.     SOM_ENDTRY
  1930. }
  1931.  
  1932. //-------------------------------------------------------------------------------------
  1933. // ODWindow: GetID
  1934. //
  1935. // Description
  1936. //-------------------------------------------------------------------------------------
  1937.  
  1938. SOM_Scope ODID  SOMLINK ODWindowGetID(ODWindow *somSelf, Environment *ev)
  1939. {
  1940.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1941.     ODWindowMethodDebug("ODWindow","GetID");
  1942.  
  1943.     return _fID;
  1944. }
  1945.  
  1946. //-------------------------------------------------------------------------------------
  1947. // ODWindow: SetID
  1948. //
  1949. // Description
  1950. //-------------------------------------------------------------------------------------
  1951.  
  1952. SOM_Scope void  SOMLINK ODWindowSetID(ODWindow *somSelf, Environment *ev,
  1953.         ODID windowID)
  1954. {
  1955.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1956.     ODWindowMethodDebug("ODWindow","SetID");
  1957.  
  1958.     _fID = windowID;
  1959. }
  1960.  
  1961. //-------------------------------------------------------------------------------------
  1962. // ODWindow: AcquireStorageUnit
  1963. //
  1964. // Description
  1965. //-------------------------------------------------------------------------------------
  1966.  
  1967. SOM_Scope ODStorageUnit*  SOMLINK ODWindowGetStorageUnit(ODWindow *somSelf, Environment *ev)
  1968. {
  1969.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1970.     ODWindowMethodDebug("ODWindow","GetStorageUnit");
  1971.     
  1972.     SOM_TRY
  1973.     
  1974.         if (_fStorageUnit != kODNULL)
  1975.             _fStorageUnit->Internalize(ev);
  1976.  
  1977.     SOM_CATCH_ALL
  1978.     SOM_ENDTRY
  1979.  
  1980.     return _fStorageUnit;
  1981. }
  1982.  
  1983. //-------------------------------------------------------------------------------------
  1984. // ODWindow: SetStorageUnit
  1985. //
  1986. // Description
  1987. //-------------------------------------------------------------------------------------
  1988.  
  1989. SOM_Scope void  SOMLINK ODWindowSetStorageUnit(ODWindow *somSelf, Environment *ev, ODStorageUnit* su)
  1990. {
  1991.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1992.     ODWindowMethodDebug("ODWindow","SetStorageUnit");
  1993.     
  1994.     SOM_TRY
  1995.  
  1996.         _fStorageUnit = su;
  1997.         su->Acquire(ev);
  1998.         
  1999.         // These below calls are unnecessary because the StdTypIO routines make sure
  2000.         // the appropriate property and value exist. -TÇ
  2001.         /*
  2002.         ODSUAddPropValue(ev, kODPropWindowRect, kODRect);
  2003.         ODSUAddPropValue(ev, kODPropWindowTitle, kODMacIText);
  2004.         ODSUAddPropValue(ev, kODPropWindowProcID, kODSShort);
  2005.         ODSUAddPropValue(ev, kODPropWindowIsVisible, kODBoolean);
  2006.         ODSUAddPropValue(ev, kODPropWindowHasCloseBox, kODBoolean);
  2007.         ODSUAddPropValue(ev, kODPropWindowHasZoomBox, kODBoolean);
  2008.         ODSUAddPropValue(ev, kODPropWindowIsResizable, kODBoolean);
  2009.         ODSUAddPropValue(ev, kODPropWindowIsRootWindow, kODBoolean);
  2010.         ODSUAddPropValue(ev, kODPropWindowIsFloating, kODBoolean);
  2011.         ODSUAddPropValue(ev, kODPropWindowRefCon, kODSLong);
  2012.         ODSUAddPropValue(ev, kODPropRootFrame, kODStrongStorageUnitRef);
  2013.         ODSUAddPropValue(ev, kODPropShouldShowLinks, kODBoolean);
  2014.         */
  2015.         
  2016.         _fIsDirty = kODTrue;
  2017.  
  2018.     SOM_CATCH_ALL
  2019.     SOM_ENDTRY
  2020. }
  2021.  
  2022. //-------------------------------------------------------------------------------------
  2023. // ODWindow: GetDraft
  2024. //
  2025. // Description
  2026. //-------------------------------------------------------------------------------------
  2027.  
  2028. SOM_Scope ODDraft*  SOMLINK ODWindowGetDraft(ODWindow *somSelf, Environment *ev)
  2029. {
  2030.     ODWindowData *somThis = ODWindowGetData(somSelf);
  2031.     ODWindowMethodDebug("ODWindow","GetDraft");
  2032.  
  2033.     return _fDraft;
  2034. }
  2035.  
  2036. //-------------------------------------------------------------------------------------
  2037. // ODWindow: GetWindowPoint
  2038. //
  2039. // Description
  2040. //-------------------------------------------------------------------------------------
  2041.  
  2042. SOM_Scope void SOMLINK ODWindowGetWindowPoint(ODWindow *somSelf, Environment *ev,
  2043.         Point* globalPoint, ODPoint* windowPoint)
  2044. {
  2045.     ODWindowData *somThis = ODWindowGetData(somSelf);
  2046.     ODWindowMethodDebug("ODWindow","GetWindowPoint");
  2047.     
  2048.     Point localCopy = *globalPoint;
  2049.     
  2050.     GrafPtr curPort;
  2051.     GetPort(&curPort);
  2052.     SetPort(_fPlatformWindow);
  2053.     SetOrigin(0,0);
  2054.     GlobalToLocal(&localCopy);
  2055.     SetPort(curPort);
  2056.     *windowPoint = (ODPoint)localCopy;
  2057. }
  2058.